<template>
  <div class="login">
    <div class="main">
      <page-head class="header_login" />
      <div class="main-inner">
        <div class="left-text-container">
          <div class="left-text">
            <p>国考云</p>
            <p>线下机考新选择</p>
            <div><span>了解详情 ></span></div>
          </div>
        </div>
        <div class="bd-container">
          <div class="bd">
            <div class="inner">
              <div class="title">{{ title }}</div>
              <div v-if="['pwd', 'sms'].includes(mode) && false" class="mode">
                <el-button
                  :class="[mode === 'pwd' ? 'selected' : '']"
                  @click="changeMode('pwd')"
                  >密码登录</el-button
                >
                <el-button
                  :class="[mode === 'sms' ? 'selected' : '']"
                  @click="changeMode('sms')"
                  >验证码登录</el-button
                >
              </div>
              <component :is="component[mode]" />
              <div v-if="['pwd', 'sms'].includes(mode) && false" class="extra">
                <el-link type="info" :underline="false" @click="reset">
                  忘记密码？
                </el-link>
              </div>
              <div
                v-else-if="mode === 'resetPassword' && false"
                class="flex justify-center"
              >
                <span class="text-[14px]">我已想起密码，</span>
                <el-link type="primary" :underline="false" @click="goLogin"
                  >直接登录</el-link
                >
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import pageHead from "./components/Header.vue";
import pwd from "./components/pwd.vue";
import sms from "./components/sms.vue";
import resetPassword from "./components/resetPassword.vue";
import { ref, watch } from "vue";
import { useLayout } from "@/layout/hooks/useLayout";
import { useDataThemeChange } from "@/layout/hooks/useDataThemeChange";
import { computed } from "vue";
import { useRoute, useRouter } from "vue-router";
defineOptions({
  name: "login"
});
// 主题布局
const { initStorage } = useLayout();
initStorage();
const { dataThemeChange } = useDataThemeChange();
dataThemeChange();
const router = useRouter();
const route = useRoute();
const mode = ref("pwd");
const changeMode = (str: string) => {
  mode.value = str;
};
const title = computed(() => {
  if (["pwd", "sms"].includes(mode.value)) {
    return "管理员登录";
  } else {
    return "重置密码";
  }
});
const component = {
  pwd,
  sms,
  resetPassword
};
// 忘记密码
const reset = () => {
  router.replace({
    path: "/login",
    query: {
      type: "resetPassword"
    }
  });
};
// 直接登录
const goLogin = () => {
  router.replace({
    path: "/login"
  });
};
// 监听路由
watch(
  route,
  () => {
    const type = route.query.type as string;
    mode.value = type ? type : "pwd";
  },
  { immediate: true }
);
</script>

<style lang="scss" scoped>
.login {
  position: relative;
  width: 100vw;
  height: 100vh;
  min-height: 750px !important;
  overflow: auto;
  background: #f7f8fd url("../../assets/bg_1.jpg") no-repeat;
  background-size: 100% 100%;

  .main {
    position: relative;
    width: 100%;
    height: 100%;
    margin: 0 auto;

    .main-inner {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 100%;
      height: 100%;

      .left-text-container {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 50%;

        .left-text {
          line-height: 60px;

          p {
            font-size: 30px;
            letter-spacing: 0.5em;
          }

          div {
            color: red;
            letter-spacing: 0.2em;
            cursor: pointer;
          }
        }
      }

      .bd-container {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 50%;

        .bd {
          padding: 30px 60px;
          background: #fff;
          border-radius: 7px;
          box-shadow: 3px 3px 5px #888;

          .inner {
            width: 315px;
            margin: 0 auto;

            .success {
              height: 40vh;
            }
          }

          .el-form-item {
            white-space: nowrap;

            &:last-child {
              text-align: center;
            }
          }

          .title {
            padding: 0 0 15px;
            margin-bottom: 20px;
            font-size: 20px;
            font-weight: 300;
            text-align: center;
          }

          .mode {
            display: flex;
            justify-content: space-between;
            margin: 20px 0 30px;

            .el-button {
              padding-right: 45px;
              padding-left: 45px;
              border: 1px solid transparent;

              &:hover,
              &:focus {
                background: #fff;
                border: 1px solid #e06563;
              }
            }

            .selected {
              color: #e06563;
              background: #fff;
              border: 1px solid #e06563;
            }
          }

          .el-button {
            margin-left: 0;
          }

          .extra {
            position: relative;
            text-align: center;

            .el-link {
              &:nth-child(2) {
                position: absolute;
                right: 0;
                font-size: 12px;
              }
            }
          }
        }
      }
    }
  }
}

@media screen and (width <= 1600px) {
  .left-text {
    left: 15% !important;
  }

  .bd {
    right: 15% !important;
  }
}
</style>
